package component.controls.ui
{
	import component.controls.interfaces.IDispose;
	import component.controls.interfaces.ITipDisplayObject;
	import component.global.manager.TipsMgr;
	import component.global.utils.FilterUtil;
	import component.global.utils.ObjectUtil;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class Component extends Sprite implements IDispose, ITipDisplayObject
	{
		public function Component()
		{
			super();
			init();
		}
		
		protected var _background:Shape;
		protected var _width:int;
		protected var _height:int;
		
		protected var _enabled:Boolean;
		
		protected var _tipData:*;
		
		/**
		 *一共有4个元素,第一个为正常状态,第二个为鼠标Over状态,第三个为鼠标Down状态,第四个为不可用状态 
		 */		
		protected var _filters:Array;
		
		protected function init():void{
			_filters = [];
			_filters.push([FilterUtil.createDropShadowFilter(45),FilterUtil.createDropShadowFilter(45,true,1)]);
			_filters.push([FilterUtil.createDropShadowFilter(45,false,2,5),FilterUtil.createGlowFilter(0x0000FF,4,true)]);
			_filters.push([FilterUtil.createDropShadowFilter(45,true,1,5),FilterUtil.createGlowFilter(0x0000FF,4)]);
			_filters.push([FilterUtil.createDropShadowFilter(45,true,1),FilterUtil.createColorMatrixFilter(FilterUtil.GRAY_MATRIX)]);
			TipsMgr.Instance.addTip(this);
		}
		
		protected function __onMouseEventHandler(e:MouseEvent):void{
			switch(e.type){
				case MouseEvent.ROLL_OVER:
				case MouseEvent.MOUSE_UP:
					_background.filters = _filters[1];
					break;
				case MouseEvent.ROLL_OUT:
					_background.filters = _filters[0];
					break;
				case MouseEvent.MOUSE_DOWN:
					_background.filters = _filters[2];
					break;
			}
		}
		
		public function set enabled(value:Boolean):void{
			_enabled = value;
			if(_enabled){
				if(_background)_background.filters = _filters[0];
			} else {
				if(_background)_background.filters = _filters[3];
			}
			mouseEnabled = mouseChildren = _enabled;
		}
		
		public function get tipData():*{
//			if(_tipData == null)_tipData = {text:"无显示内容"};
			return _tipData;
		}
		
		public function set tipData(data:*):void{
			_tipData = data;
		}
		
		public function get tipType():String{
			return null;
		}
		
		public function get asDisplayObject():DisplayObject{
			return this as DisplayObject;
		}
		
		public function dispose():void{
			TipsMgr.Instance.removeTip(this);
			ObjectUtil.dispose(_background);_background = null;
			_filters = null;
			_tipData = null;
		}
	}
}